import java.util.Arrays;
import java.util.concurrent.*;

/**
 * @program: thread
 * @ClassName ThreadTest
 * @description:
 * @author: yaoguipei
 * @create: 2021-08-08 11:26
 * @Version 1.0
 **/
public class ThreadTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //方法一
        new MyThread().start();
        //方法二
        new Thread(new MyRun()).start();
        //方法三 lambda
        new Thread(()->{
            System.out.println("hello Lambda");
        }).start();

        //方法四 线程池
        ExecutorService service = Executors.newCachedThreadPool();
        service.execute(()->{
            System.out.println("hello ThreadPool");
        });

        //方法五
        Future<String> f = service.submit(new MyCall());
        String s = f.get();
        System.out.println(s);

        service.shutdown();

        //方法五
        FutureTask<String> task = new FutureTask<>(new MyCall());
        Thread t = new Thread(task);
        t.start();
        System.out.println(task.get());
    }
}

class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("MyThread.run");
    }
}

class MyRun implements Runnable{

    @Override
    public void run() {
        System.out.println("MyRun.run");
    }
}

class MyCall implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println("MyCall.call");
        return "success";
    }
}